import request from "@/utils/request";

const PRODUCTSPECOPTION_BASE_URL = "/api/v1/productSpecOptions";

const ProductSpecOptionAPI = {
  /** 获取规格选项分页数据 */
  getPage(queryParams?: ProductSpecOptionPageQuery) {
    return request<any, PageResult<ProductSpecOptionPageVO[]>>({
      url: `${PRODUCTSPECOPTION_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },
  /**
   * 获取规格选项表单数据
   *
   * @param id 规格选项ID
   * @returns 规格选项表单数据
   */
  getFormData(id: number) {
    return request<any, ProductSpecOptionForm>({
      url: `${PRODUCTSPECOPTION_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /** 添加规格选项*/
  add(data: ProductSpecOptionForm) {
    return request({
      url: `${PRODUCTSPECOPTION_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 更新规格选项
   *
   * @param id 规格选项ID
   * @param data 规格选项表单数据
   */
  update(id: number, data: ProductSpecOptionForm) {
    return request({
      url: `${PRODUCTSPECOPTION_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  /**
   * 批量删除规格选项，多个以英文逗号(,)分割
   *
   * @param ids 规格选项ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${PRODUCTSPECOPTION_BASE_URL}/${ids}`,
      method: "delete",
    });
  },
};

export default ProductSpecOptionAPI;

/** 规格选项分页查询参数 */
export interface ProductSpecOptionPageQuery extends PageQuery {}

/** 规格选项表单对象 */
export interface ProductSpecOptionForm {
  id?: number;
  specId?: number;
  /** 选项名称(如:微辣) */
  name?: string;
  /** 价格调整 */
  priceAdjustment?: number;
  /** 选项图片 */
  image?: string;
  sort?: number;
}

/** 规格选项分页对象 */
export interface ProductSpecOptionPageVO {
  id?: number;
  specId?: number;
  /** 选项名称(如:微辣) */
  name?: string;
  /** 价格调整 */
  priceAdjustment?: number;
  /** 选项图片 */
  image?: string;
  sort?: number;
}
